<?php 
header("content-type:text/html;charset=utf8");
$jsApiParameters = urldecode($_GET['data']);
 ?>
<script type="text/javascript">
var jsApiParams = <?php echo $jsApiParameters; ?>
    //调用微信JS api 支付
    function jsApiCall() {
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                jsApiParams,
                function (res) {
                    WeixinJSBridge.log(res.err_msg);
                    var msg = res.err_msg.substr(-2);
                    if (msg == 'ok') {
                        WeixinJSBridge.call('closeWindow');
                    }else{
                        window.location.href='https://pay.hispot.cn/app/h5/error.html';
                    }
                }
        );
    }

    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }

    window.onload = function() {
        callpay();
    }
</script>
